<template>
    <view>
        <block v-if="list && list.length>0">
            <view class="article-list" v-if="list && list.length>0">
                <view class="article-card" v-for="(item,index) in list" :key="index">
                    <view class="article-header u-flex u-row-between" @click="onClick(item,'view')">
                        <text class="article-title u-font-bold"
                            :class="msgMode?(item.read? 'read' : 'unread'):''">{{item.title}}</text>
                    </view>
                    <view class="article-footer u-flex u-row-between title-row">
                        <view class="time-info u-flex u-col-center">
                            <uni-icons type="calendar" size="14" color="#888"></uni-icons>
                            <text class="time-text">{{timePlaceholder}}：{{item.time}}</text>
                        </view>
                        <view class="read-more u-flex u-col-center" v-if="item.tag">
                            <text class="more-text">{{item.tag}}</text>
                        </view>
                    </view>

                    <view class="u-flex u-row-between u-col-center info-row" v-if="showBtn">
                        <view class="record-btn u-flex u-row-center u-col-center" @click="onClick(item,'edit')">
                            <text class="u-font-24 btn-text">修改</text>
                        </view>
                        <view class="record-btn u-flex u-row-center u-col-center" @click="onClick(item,'del')">
                            <text class="u-font-24 btn-text">删除</text>
                        </view>
                    </view>
                    <view class="unread-indicator" v-if="msgMode&&!item.read"></view>
                </view>

            </view>

            <view class="load-more">
                <uni-load-more :status="loadStatus"></uni-load-more>
            </view>
        </block>

        <!-- 空状态 -->
        <view class="empty-container u-flex-col u-row-center u-col-center" v-else>
            <text class="u-font-28 empty-text">暂无内容</text>
            <text class="u-font-26 empty-tip"></text>
        </view>


        <dfer-button @clickHandler="handleAddClick" title="新增" type="0" v-if="showBtn" />
    </view>

</template>

<script>
    /**
     * 带搜索功能的下拉框
     * @description 此组件一般用于表单下拉框。
     * @tutorial https://www.dfer.site
     * @property {Array} list 下拉框选项
     * @event {Function} selectHandler 选择下拉框会触发此事件
     * @example <dfer-picker @selectHandler="selectItem" :selectList="item.arr" placeholder="请输入关键词" :extend="index" />
     */
    export default {
        name: "dfer-list-article",
        data() {
            return {
                status: '',
            };
        },
        props: {
            list: {
                type: Array,
                default () {
                    return [{
                        title: '标题',
                        tag: '标签',
                        time: '2025年10月16日'
                    }]
                }
            },
            showBtn: {
                type: Boolean,
                default () {
                    return true
                }
            },
            msgMode: {
                type: Boolean,
                default () {
                    return false
                }
            },
            trace: {
                type: Boolean,
                default () {
                    return false
                }
            },
            timePlaceholder: {
                type: String,
                default () {
                    return "发布时间"
                }
            },
            loadStatus: {
                type: String,
                default: 'loadmore'
            }
        },
        watch: {
            list: {
                handler(newVal) {
                    console.log('handler', newVal);
                },
                immediate: true
            }
        },
        created() {},
        methods: {
            onClick(item, type) {
                if (this.trace)
                    console.log(item, type);
                this.$emit('clickHandler', item, type);
            },
            handleAddClick() {
                this.onClick(null, 'add');
            }
        }
    }
</script>

<style lang="scss" scoped>
    page {
        background-color: #f5f7fa;
    }

    .container {
        background-color: #f5f7fa;
        min-height: 100vh;
        padding-bottom: 140rpx;
    }

    /* 搜索区域 */
    .search-card {
        background-color: #ffffff;
        border-radius: 12rpx;
        padding: 20rpx;
        margin-bottom: 20rpx;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
    }

    .search-input {
        flex: 1;
        background-color: #f8f9fa;
        border-radius: 8rpx;
        padding: 0 20rpx;
        height: 70rpx;
        margin-right: 20rpx;
    }

    .input-field {
        flex: 1;
        height: 70rpx;
        font-size: 28rpx;
        margin-left: 10rpx;
    }

    .search-btn {
        width: 140rpx;
        height: 70rpx;
        border-radius: 8rpx;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .btn-text {
        font-size: 28rpx;
        color: #ffffff;
    }

    /* 文章列表 */
    .article-list {
        padding: 24rpx;
    }

    .article-card {
        background: #ffffff;
        border-radius: 16rpx;
        margin-bottom: 24rpx;
        box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.04);
        border-left: 6rpx solid $main-color;
        padding: 32rpx;
        position: relative;
        overflow: hidden;

        // 政府风格的装饰线条
        &::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 2rpx;
            background: $main-background-linear;
        }
    }

    .article-header {
        margin-bottom: 20rpx;
    }

    .article-title {
        font-size: 30rpx;
        color: #333333;
        line-height: 1.4;
        flex: 1;
        padding-right: 20rpx;
    }

    .unread {
        color: #333333 !important;
        font-weight: 500;
    }

    .read {
        color: #999999 !important;
    }

    .unread-indicator {
        position: absolute;
        top: 32rpx;
        right: 20rpx;
        width: 16rpx;
        height: 16rpx;
        background-color: #ff3b30;
        border-radius: 50%;
    }

    .article-footer {
        width: 100%;
    }

    .time-info {
        font-size: 24rpx;
        color: #888888;
    }

    .time-text {
        margin-left: 8rpx;
    }

    .read-more {
        font-size: 24rpx;
        // color: $main-color;
    }

    .more-text {
        margin-right: 8rpx;
    }

    .title-row {
        margin-bottom: 24rpx;
        width: 100%;
    }

    .info-row {
        width: 100%;
    }

    .card-title {
        font-size: 32rpx;
        color: #1a3260;
        font-weight: 600;
        line-height: 1.4;
        letter-spacing: 0.5rpx;
    }

    .record-time {
        color: #7a8aa6;
        background: #f0f4ff;
        padding: 8rpx 20rpx;
        border-radius: 16rpx;
        font-size: 22rpx !important;
    }

    .record-btn {
        width: 45%;
        height: 56rpx;
        border-radius: 28rpx;
        background: $main-background-linear;
        box-shadow: 0 4rpx 16rpx $main-color;
        transition: all 0.3s ease;
    }

    .record-btn:active {
        transform: scale(0.95);
        box-shadow: 0 2rpx 8rpx rgba(43, 92, 255, 0.2);
    }

    .btn-text {
        color: #ffffff;
        font-weight: 500;
        letter-spacing: 0.5rpx;
    }

    .empty-container {
        padding-top: 200rpx;
        text-align: center;
    }

    .empty-image {
        width: 240rpx;
        height: 240rpx;
        margin-bottom: 32rpx;
        opacity: 0.7;
    }

    .empty-text {
        color: #4a638c;
        margin-top: 32rpx;
        font-weight: 500;
        letter-spacing: 0.5rpx;
    }

    .empty-tip {
        color: #7a8aa6;
        margin-top: 16rpx;
        letter-spacing: 0.5rpx;
    }

    .footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 24rpx 32rpx 40rpx;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #ffffff 20%);
        z-index: 10;
    }

    .footer-btn {
        height: 96rpx;
        border-radius: 48rpx;
        background: $main-background-linear;
        box-shadow: 0 8rpx 32rpx $main-color;
        position: relative;
        transition: all 0.3s ease;
        padding: 0 40rpx;
    }

    .footer-btn:active {
        transform: translateY(2rpx);
        box-shadow: 0 4rpx 16rpx $main-color;
    }

    .add-icon {
        font-family: 'iconfont' !important;
        font-size: 36rpx;
        color: #ffffff;
        margin-left: 12rpx;
    }

    .load-more {
        padding: 30rpx 0;
        text-align: center;
    }

    /* 加载更多样式 */
    .uni-load-more {
        margin: 30rpx 0;
    }
</style>